//
//  MineViewModel.swift
//  Exchange
//
//  Created by rui on 2018/4/23.
//  Copyright © 2018年 common. All rights reserved.
//

import Foundation



class MineViewModel: BaseViewModel {
    
    var dataArray = [
        ["icon":"mine_asset","title":kText("我的资产")],
        ["icon":"mine_address","title":kText("提币地址")],
        ["icon":"mine_safeCenter","title":kText("安全中心")],
        ["icon":"mine_help","title":kText("帮助中心")]
//        ["icon":"mine_invite","title":kText("推荐Coingo")]
    ]
    
    private lazy var userInfoApi: UserAccountInfoRequest = {
        let login = UserAccountInfoRequest()
        login.dataReformer = self
        login.paramSource = self
        login.delegate = self
        return login
    }()
    
    ///刷新用户信息
    func refreshUserinfo() {
        self.userInfoApi.loadData()
    }
}

extension MineViewModel: RequestCallBack,RequestDataReformer,RequestParamSource {
    
    func reform(_ request: BaseRequest, _ data: [String : Any]?) {
        dPrint(data)
        if let _ = request as? UserAccountInfoRequest {
            if let userInfo = data?["data"] as? [String:Any] {
                let appInfo = AppInfo.default
                appInfo.install(data: userInfo)
            }
            self.response?(ResponseState.mine_userinfo,true, nil)
        }
    }
    
    func requestDidSucess(_ request: BaseRequest) {
        
    }
    
    func requestDidFail(_ request: BaseRequest) {
        if let _ = request as? UserAccountInfoRequest {
            self.response?(ResponseState.mine_userinfo,false, request.errorMsg)
        }
    }
    
    func requestParams(_ request: BaseRequest) -> [String : Any]? {
      return nil
    }
    
}
